
foreach prd in POS PPO {

use "$output\analysis_areas_`prd'.dta", clear
levelsof pt_cbsa, local(area)

use "$temp\cbsa_`prd'_11_data.dta", clear
append using "$temp\cbsa_`prd'_12_data.dta"
append using "$temp\cbsa_`prd'_13_data.dta"
append using "$temp\cbsa_`prd'_14_data.dta"
destring yr, replace
save "$temp\cbsa_`prd'_all years.dta", replace

*** log-log models		
clear
save "$temp\reg_coeffs_`prd'_all years_log_log.dta", replace emptyok 
foreach a of local area {
		
		use "$temp\cbsa_`prd'_all years.dta", clear
		keep if analysis_area == "`a'"
		
		if _N>10 { 
				
			di "Analysis area: `a'"
				
			reg ln_price ln_wtp ln_beds ln_mcr ln_mcd teaching forprofit ftres non_cbsa i.yr [aweight = patients], cluster(sys_hosp)
			outreg2 using "$exp\WTP_regs_`prd'_all years_log_log_`d'.xls", adjr2 ctitle("`a'", ln_Price-ln_WTP_PP, Admit Wtd, System SEs)
			
			regsave, pval ci level(95)
			gen year = "all years"
			gen prod = "`prd'"
			gen analysis_area = "`a'"
			
			append using "$temp\reg_coeffs_`prd'_all years_log_log.dta"
			save "$temp\reg_coeffs_`prd'_all years_log_log.dta", replace
		}
			
		else {
			di " * * * * * * * * * * * * * * * * * * * * * * "	
			di "Analysis area: `a' - less than 10 observations"
			di " * * * * * * * * * * * * * * * * * * * * * * "
			clear
		}
		
	}

***log-linear models
clear
save "$temp\reg_coeffs_`prd'_all years_log_linear.dta", replace emptyok 		
foreach a of local area {
		
		use "$temp\cbsa_`prd'_all years.dta", clear
		keep if analysis_area == "`a'"
		
		if _N>10 { 
				
			di "Analysis area: `a'"
				
			reg ln_price wtp_pp bdtot pct_mcr pct_mcd teaching forprofit ftres non_cbsa i.yr [aweight = patients], cluster(sys_hosp)
			outreg2 using "$exp\WTP_regs_`prd'_all years_log_linear_`d'.xls", adjr2 ctitle("`a'", ln_Price-WTP_PP, Admit Wtd, System SEs)
			
			regsave, pval ci level(95)
			gen year = "all years"
			gen prod = "`prd'"
			gen analysis_area = "`a'"
			
			append using "$temp\reg_coeffs_`prd'_all years_log_linear.dta"
			save "$temp\reg_coeffs_`prd'_all years_log_linear.dta", replace
		}
			
		else {
			di " * * * * * * * * * * * * * * * * * * * * * * "	
			di "Analysis area: `a' - less than 10 observations"
			di " * * * * * * * * * * * * * * * * * * * * * * "
			clear
		}
		
	}

***linear models
clear
save "$temp\reg_coeffs_`prd'_all years_linear.dta", replace emptyok 		
foreach a of local area {
		
		use "$temp\cbsa_`prd'_all years.dta", clear
		keep if analysis_area == "`a'"
		
		if _N>10 { 
				
			di "Analysis area: `a'"
				
			reg hosp_price wtp_pp bdtot pct_mcr pct_mcd teaching forprofit ftres non_cbsa i.yr [aweight = patients], cluster(sys_hosp)
			outreg2 using "$exp\WTP_regs_`prd'_all years_linear_`d'.xls", adjr2 ctitle("`a'", ln_Price-WTP_PP, Admit Wtd, System SEs)
			
			regsave, pval ci level(95)
			gen year = "all years"
			gen prod = "`prd'"
			gen analysis_area = "`a'"
			
			append using "$temp\reg_coeffs_`prd'_all years_linear.dta"
			save "$temp\reg_coeffs_`prd'_all years_linear.dta", replace
		}
			
		else {
			di " * * * * * * * * * * * * * * * * * * * * * * "	
			di "Analysis area: `a' - less than 10 observations"
			di " * * * * * * * * * * * * * * * * * * * * * * "
			clear
		}
		
	}

***linear models - trimmed 5% each side
clear
save "$temp\reg_coeffs_`prd'_all years_linear_trimmed.dta", replace emptyok 		
foreach a of local area {
		
		use "$temp\cbsa_`prd'_all years.dta", clear
		keep if analysis_area == "`a'"
		
		if _N>10 { 
				
			di "Analysis area: `a'"
			
			sum hosp_price, det
			drop if hosp_price < r(p5)
			drop if hosp_price > r(p95)
			
			reg hosp_price wtp_pp bdtot pct_mcr pct_mcd teaching forprofit ftres non_cbsa i.yr [aweight = patients], cluster(sys_hosp)
			outreg2 using "$exp\WTP_regs_`prd'_all years_linear_trimmed_`d'.xls", adjr2 ctitle("`a'", ln_Price-WTP_PP, Admit Wtd, System SEs)
			
			regsave, pval ci level(95)
			gen year = "all years"
			gen prod = "`prd'"
			gen analysis_area = "`a'"
			
			append using "$temp\reg_coeffs_`prd'_all years_linear_trimmed.dta"
			save "$temp\reg_coeffs_`prd'_all years_linear_trimmed.dta", replace
		}
			
		else {
			di " * * * * * * * * * * * * * * * * * * * * * * "	
			di "Analysis area: `a' - less than 10 observations"
			di " * * * * * * * * * * * * * * * * * * * * * * "
			clear
		}
		
	}

}


